﻿using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Application.AppEquipmentLayoutManage;
using Zocono.WCS.Application.AppEquipmentManage;
using Zocono.WCS.Application.AppHynnStateUp;
using Zocono.WCS.Application.AppLogManage;
using Zocono.WCS.Application.AppPlcManage;
using Zocono.WCS.Application.AppTelegramRecordManage;
using Zocono.WCS.Application.AppTraces;
using Zocono.WCS.Application.AppUserManage;
using Zocono.WCS.Domain.BytesMapObjectDomain;
using Zocono.WCS.Domain.DomainRepository;
using Zocono.WCS.Domain.ElevatorManage;
using Zocono.WCS.Domain.EquipmentLayoutManageDomain;
using Zocono.WCS.Domain.EquipmentManageDomain;
using Zocono.WCS.Domain.EquipmentProcessDomain.PlanarGeneralMessage;
using Zocono.WCS.Domain.HynnStateUpDomain;
using Zocono.WCS.Domain.JobDomain;
using Zocono.WCS.Domain.LogDomain;
using Zocono.WCS.Domain.MonitorDomain;
using Zocono.WCS.Domain.PlanarProcessServiceMapDomain;
using Zocono.WCS.Domain.PlcConnectionDomain;
using Zocono.WCS.Domain.PlcConnectPoolDomain;
using Zocono.WCS.Domain.PlcPointDomain;
using Zocono.WCS.Domain.PlcReadDbDomain;
using Zocono.WCS.Domain.PlcWriteBoMangeDomain;
using Zocono.WCS.Domain.PlcWriteDbDomain;
using Zocono.WCS.Domain.ProgrameDomain;
using Zocono.WCS.Domain.RouteDomain;
using Zocono.WCS.Domain.ScGetWMSTaskDomain;
using Zocono.WCS.Domain.ScRowDomain;
using Zocono.WCS.Domain.ScWorkModelDomain;
using Zocono.WCS.Domain.StationDomain;
using Zocono.WCS.Domain.TelegramRecordInfoDomain;
using Zocono.WCS.Domain.UserManageDomain;
using Zocono.WCS.Domain.WcsGetWmsJobDomain;
using Zocono.WCS.Domain.WorkTaskDomain;
using Zocono.WCS.Infrastructure.Repository;

namespace Zocono.WCS.Admin
{
    public static class ServiceIOC
    {
        public static void AddService(IServiceCollection services)
        {

            services.AddSingleton<ISnowflake, Snowflake>();
            //services.AddScoped<ApiBase>();

            //请求信息
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
            //添加session
            services.AddDistributedMemoryCache();
            services.AddSession(options =>
            {
                // 设置 Session 过期时间15分钟
                options.IdleTimeout = TimeSpan.FromMinutes(15);
            });

            //用户信息
            services.AddScoped<IUserRepository, UserRepository>();
            services.AddScoped<IUser, User>();
            services.AddScoped<IUserService, UserService>();
            services.AddScoped<UserApp>();
            services.AddScoped<IRoleFunctionRepository, RoleFunctionRepository>();
            services.AddScoped<IFunctionRepository, FunctionRepository>();
            services.AddScoped<IRoleRepository, RoleRepository>();
            //操作日志
            services.AddScoped<ITracesRepository, TracesRepository>();
            services.AddScoped<ITracesService, TracesService>();
            services.AddScoped<TracesApp>();
            //设备管理
            services.AddScoped<EquipmentApp>();
            services.AddScoped<IDispatchEquipmentService, DispatchEquipmentService>();
            services.AddScoped<IEquipmentTypeService, EquipmentTypeService>();
            services.AddScoped<IEquipmentTypeRepository, EquipmentTypeRepository>();
            services.AddScoped<IDispatchEquipmentRepository, DispatchEquipmentRepository>();
            services.AddScoped<EquipmentLayoutApp>();
            services.AddScoped<IEquipmentLayoutTypeService, EquipmentLayoutTypeService>();
            services.AddScoped<IEquipmentLayoutTypeRepository, EquipmentLayoutTypeRepository>();
            services.AddScoped<IEquipmentLayoutService, EquipmentLayoutService>();
            services.AddScoped<IEquipmentLayoutRepository, EquipmentLayoutRepository>();



            services.AddScoped<IElevatorInfoRepository, ElevatorInfoRepository>();
            services.AddScoped<IElevatorJudgeInfoRepository, ElevatorJudgeInfoRepository>();

            services.AddScoped<IElevatorMasterInfoRepository, ElevatorMasterInfoRepository>();

            //配置管理
            //程序配置
            services.AddScoped<ProgrameInfoApp>();
            services.AddScoped<IProgrameService, ProgrameService>();
            services.AddScoped<IProgrameInfoRepository, ProgrameInfoRepository>();
            //作业配置
            services.AddScoped<JobInfoApp>();
            services.AddScoped<IJobInfoService, JobInfoService>();
            services.AddScoped<IJobInfoRepository, JobInfoRepository>();
         
            //PLC连接配置
            services.AddScoped<PlcConnectionInfoApp>();
            services.AddScoped<IPlcConnectionInfoRepository, PlcConnectionInfoRepository>();
            services.AddScoped<IPlcConnectionInfoService, PlcConnectionInfoService>();
            #region plc连接信息查询
            services.AddScoped<IPlcConnectionLockInfoRepository, PlcConnectionLockInfoRepository>();
            services.AddScoped<IPlcConnectionStateInfoRepository, PlcConnectionStateInfoRepository>();
            #endregion
            services.AddScoped<LogApp>();
            services.AddScoped<IOperateLogInfoRepository, OperateLogInfoRepository>();
            services.AddScoped<IOperateLogService, OperateLogService>();

            //PLC点位配置
            services.AddScoped<PlcPointInfoApp>();
            services.AddScoped<IPlcPointInfoRepositpry, PlcPointInfoRepository>();
            services.AddScoped<IPlcPointInfoService, PlcPointInfoService>();

            //平面设备报文业务处理配置
            services.AddScoped<IPlanarProcessServiceMapInfoRepository, PlanarProcessServiceMapInfoRepository>();
            services.AddScoped<IPlanarProcessServiceMapService, PlanarProcessServiceMapService>();
            services.AddScoped<PlanarProcessServiceMapApp>();

            //plc 读db 配置
            services.AddScoped<IPlcReadDbInfoRepository, PlcReadDbInfoRepository>();
            services.AddScoped<IPlcReadDbInfoService, PlcReadDbInfoService>();
            services.AddScoped<PlcReadDbInfoApp>();

            //plc 写db 配置
            services.AddScoped<IPlcWriteDbInfoRepository, PlcWriteDbInfoRepository>();
            services.AddScoped<IPlcWriteDbInfoService, PlcWriteDbInfoService>();
            services.AddScoped<PlcWriteDbInfoApp>();

            //报文解析配置
            services.AddScoped<IBytesMapObjectInfoRepository, BytesMapObjectInfoRepository>();
            services.AddScoped<IBytesMapObjectInfoService, BytesMapObjectInfoService>();
            services.AddScoped<BytesMapObjectInfoApp>();
            //工位信息配置
            services.AddScoped<StationInfoApp>();
            services.AddScoped<IStationInfoRepository, StationInfoRepository>();
            services.AddScoped<IStationInfoService, StationInfoService>();


            services.AddScoped<ElevatorInfoApp>();
            

            //路径配置
            services.AddScoped<RouteInfoApp>();
            services.AddScoped<IRouteInfoRepository, RouteInfoRepository>();
            services.AddScoped<IRouteInfoService, RouteInfoService>();

            //路径明细配置
            services.AddScoped<RouteDetailInfoApp>();
            services.AddScoped<IRouteDetailInfoRepository, RouteDetailInfoRepository>();
            services.AddScoped<IRouteDetailInfoService, RouteDetailInfoService>();

            //堆垛机-货架排号配置
            services.AddScoped<ScRowInfoApp>();
            services.AddScoped<IScRowInfoRepository, ScRowInfoRepository>();
            services.AddScoped<IScRowInfoService, ScRowInfoService>();
            //堆垛机作业模式
            services.AddScoped<ScWorkModelApp>();
            services.AddScoped<IScWorkModelInfoRepository, ScWorkModelInfoRepository>();
            services.AddScoped<IScWorkModelService, ScWorkModelService>();


            services.AddScoped<IElevatorInfoService, ElevatorInfoService>();
            services.AddScoped<IElevatorJudgeInfoService, ElevatorJudgeInfoService>();
            services.AddScoped<IElevatorMasterInfoService, ElevatorMasterInfoService>();


            #region 任务管理

            //任务管理
            services.AddScoped<WorkTaskInfoApp>();
            services.AddScoped<IWorkTaskInfoRepository, WorkTaskInfoRepository>();
            services.AddScoped<IWorkTaskInfoServeice, WorkTaskInfoServeice>();
            services.AddScoped<IScGetWMSTaskService, ScGetWMSTaskService>();
            //历史任务
            services.AddScoped<HistoryWorkTaskInfoApp>();
            services.AddScoped<IHistoryWorkTaskInfoRepository, HistoryWorkTaskInfoRepository>();
            services.AddScoped<IHistoryWorkTaskInfoServeice, HistoryWorkTaskInfoServeice>();

            services.AddScoped<TaskRouteDetailRecordInfoApp>();
            services.AddScoped<ITaskRouteDetailRecordInfoRepository, TaskRouteDetailRecordInfoRepository>();
            services.AddScoped<ITaskRouteDetailRecordInfoService, TaskRouteDetailRecordInfoService>();
            services.AddScoped<IWcsGetWmsJobService, WcsGetWmsJobService>();




            #endregion

            //报文存储
            services.AddScoped<TelegramRecordApp>();
            services.AddScoped<ITelegramRecordInfoService, TelegramRecordInfoService>();
            services.AddScoped<ITelegramRecordInfoRepository, TelegramRecordInfoRepository>();

            //服务，平面正常动作报文业务处理服务工厂
            services.AddScoped<IPlanarGeneralPlcActionProcessServiceFactory, PlanarGeneralPlcActionProcessServiceFactory>();//工厂
            services.AddScoped<IDispatchEquipmentPlanarStateRepository, DispatchEquipmentPlanarStateRepository>();
            services.AddScoped<IDispatchEquipmentRepository, DispatchEquipmentRepository>();

            //ELE            
            services.AddScoped<IElevatorJudgeInfoRepository, ElevatorJudgeInfoRepository>();
            services.AddScoped<IElevatorInfoRepository, ElevatorInfoRepository>();



            //日志
            services.AddScoped<IInterfaceLogRepository, InterfaceLogRepository>();
            services.AddScoped<IRunLogRepository, RunLogRepository>();
            services.AddScoped<IRunLogInfoService, RunLogInfoService>();
            services.AddScoped<IInterfaceLogInfoService, InterfaceLogInfoService>();

            //PLC操作
            services.AddScoped<PlcWriteBoMange>();
            services.AddScoped<IPlcWriteBoService, PlcWriteBoService>();
            services.AddSingleton<IPlcConnectionPool, PlcConnectionPool>();
            //services.AddScoped<IPlcConnectionPoolService, PlcConnetionPoolService>();
            //监控
            services.AddScoped<MonitorApp>();
            services.AddScoped<IMonitorConfigInfoRepository, MonitorConfigInfoRepository>();
            services.AddScoped<IMonitorConfigInfoService, MonitorConfigInfoService>();

            //恒翼能设备状态保存
            services.AddScoped<HynnStateUpApp>();
            services.AddScoped<IHynnStateUpService, HynnStateUpService>();
            services.AddScoped<IRedisHelper, RedisHelper>();
        }
    }
}
